<?php
/**
 * Crmlite_View_Helper_UrlParams
 *
 * @final
 * @package Crmlite_App
 * @version $Id: UrlParams.php 28 2007-08-30 04:15:14Z etng2004 $
 * @copyright 2006-2007 ETE.CN
 * @author Yi BO  <etng2004@gmail.com>
 * @license PHP Version 3.0 {@link http://www.php.net/license/3_0.txt}
 */
class Crmlite_View_Helper_UrlParams
{
    /**
     * view
     *
     * @var Zend_View_Interface
     * @access public
     */
    public $view;

    /**
     * setView
     *
     * @param Zend_View_Interface $view
     * @access public
     * @return Zend_View_Interface
     */
    public function setView(Zend_View_Interface $view)
    {
        $this->view = $view;
        return $this->view;
    }

    /**
     * urlParams
     *
     * @param array $params			参数数组
     * @param boolean $traditional	是否采用旧式的参数传递方式
     * @access public
     * @return string
     */
    public function urlParams($params = array(), $traditional = false)
    {
        $request = $this->view->controller->getRequest();
        $params = $params + $request->getParams();
        if ($traditional)
        {
            $url = '/index.php?' . http_build_query($params);
        }
        else
        {
            // 另存并清除参数中的模块、控制器、动作
            $module 	= $params['module'];unset($params['module']);
            $controller = $params['controller'];unset($params['controller']);
            $action 	= $params['action'];unset($params['action']);
            // 组合 url
            $url = '/' . $module . '/' . $controller . '/' . $action . '/';
            $url .= str_replace('=', '/', http_build_query($params, '', '/'));
        }
        return $url;
    }
}
